#!/bin/bash
#
# Results taken from:
#   Luo, H., Baum, J. D., Lohner, R. (2003)
#   "On the computation of multi-material flows using ALE formulation"
#   Journal of Computational Physics, 194, 304-328
. $WM_PROJECT_DIR/bin/tools/RunFunctions
createEpsP()
{

    gnuplot<<EOF
    set terminal postscript eps enhanced color font 'Helvetica,40' linewidth 2\
        dl 8.0
    set output "blastFoam_shockTube_validation_p.eps"
    set xlabel "X-Position (m)"
    set ylabel "Pressure [Pa]"
    set grid
    set key right top
    set key on
    set size 2,2
    set autoscale
    plot    "$1" using 1:2 title 'Tabulated' \
            with lines lt 1 linewidth 2 linecolor rgb 'black', \
            "$2" using 1:2 every 20 title 'Ideal gas' \
            with points pt 5 ps 3 linecolor rgb 'red'
EOF
}

createEpsRho()
{

    gnuplot<<EOF
    set terminal postscript eps enhanced color font 'Helvetica,40' linewidth 2\
        dl 8.0
    set output "blastFoam_shockTube_rho.eps"
    set xlabel "X-Position (m)"
    set ylabel "Density [kg/m^3]"
    set grid
    set key right top
    set key on
    set size 2,2
    set autoscale
    plot    "$1" using 1:3 title 'Tabulated' \
            with lines lt 1 linewidth 2 linecolor rgb 'black', \
            "$2" using 1:3 every 20 title 'Ideal gas' \
            with points pt 5 ps 3 linecolor rgb 'red'
EOF
}

createEpsUx()
{

    gnuplot<<EOF
    set terminal postscript eps enhanced color font 'Helvetica,40' linewidth 2\
        dl 8.0
    set output "blastFoam_shockTube_validation_Ux.eps"
    set xlabel "X-Position (m)"
    set ylabel "Velocity [m/s]"
    set grid
    set key left top
    set key on
    set size 2,2
    set autoscale
    plot    "$1" using 1:2 title 'Tabulated' \
            with lines lt 1 linewidth 2 linecolor rgb 'black', \
            "$2" using 1:2 every 20 title 'Ideal gas' \
            with points pt 5 ps 3 linecolor rgb 'red'
EOF
}

# test if gnuplot exists on the system
if ! which gnuplot > /dev/null 2>&1
then
    echo "gnuplot not found - skipping graph creation" >&2
    exit 1
fi

# paths to data
VALIDATIONDATAROOT=./validationData

time=$(foamListTimes -latestTime -case ../)
pRhoBlastFOAM="../postProcessing/sampleDict/$time/Centerline_p*"
UBlastFOAM="../postProcessing/sampleDict/$time/Centerline_U*"

pRhoIdeal="data/Centerline_p*"
UIdeal="data/Centerline_U*"

createEpsP $pRhoBlastFOAM $pRhoIdeal
createEpsRho $pRhoBlastFOAM $pRhoIdeal
createEpsUx $UBlastFOAM $UIdeal

echo Done
